package com.ease.framework.workbench.spi.impls {
	import com.ease.framework.workbench.spi.ICommand;

	/**
	 * 复合的Command类.
	 *
	 * 此Command执行前，会将其索引的command先执行.
	 *
	 * @author huchangcheng
	 *
	 */
	public class CompoundCommand extends Command {

		private var _commandlist:Array;

		public function CompoundCommand() {
			super();
			_commandlist = new Array();
		}

		public function addCommand(command:ICommand):void {
			this._commandlist.push(command);
		}

		override public function execute():void {
			var length:int = this._commandlist.length;

			if(length == 0) return;
			for (var i:int=length-1;i>=0;i--){
				var command:Command = this._commandlist[i];
				if(command)
					command.execute();
			}
		}

		override public function undo():void {
			var length:int = this._commandlist.length;
			if(length == 0) return;

			for (var i:int=0;i<length;i++){
				var command:Command = this._commandlist[i];
				if(command)
					command.undo();
			}
			//_commandlist.splice(0,_commandlist.length);
		}

		public function get commandList():Array {
			return this._commandlist;
		}
	}
}